package com.controller;

import com.biz.IBooktypeBiz;
import com.entity.Booktype;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/booktype")
public class BooktypeAction {
    @Autowired
    private IBooktypeBiz booktypeBiz;

    //列表
    @RequestMapping("/list")
    @ResponseBody
    public List<Booktype> getAll(){
       return  booktypeBiz.getAll();
    }

    //增加
    @RequestMapping("/add")
    public String addBooktype(Booktype booktype){
        booktypeBiz.addType(booktype);
        return "back/booktype_list";
    }

    //修改前获取一个
    @RequestMapping("/getbyid/n")
    public ModelAndView getByid(@PathVariable(value = "n") int tid){
        ModelAndView mv=new ModelAndView( "/back/booktype_mod");
       Booktype booktype= booktypeBiz.getById(tid);
        mv.addObject("booktype",booktype);
        return mv;
    }
    //修改
    @RequestMapping("/mod")
    public String modBooktype(Booktype booktype){
        booktypeBiz.modType(booktype);
        return "back/booktype_list";
    }

    //删除
    @RequestMapping("/del")
    public String delBooktype(int tid){
        booktypeBiz.delType(tid);
        return "back/booktype_list";
    }

}
